package com.iframework.tools;

import java.text.SimpleDateFormat;
import java.util.Date;

public class BaseTools {

	/**
	 * 数组合并
	 * @param a数组
	 * @param b数组
	 * @return 合并后的a+b数组组合
	 */
    public static <T> T[] concat(T[] a, T[] b) {
        final int alen = a.length;
        final int blen = b.length;
        if (alen == 0) {
            return b;
        }
        if (blen == 0) {
            return a;
        }
        final T[] result = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), alen + blen);
        System.arraycopy(a, 0, result, 0, alen);
        System.arraycopy(b, 0, result, alen, blen);
        return result;
    }
    
   
    
    /**
     * 按格式返回当前时间
     * @param Formatter 时间格式
     * @return 按格式返回当前时间
     */
    public static String getNow(String Formatter){
    	SimpleDateFormat dateFormat = new SimpleDateFormat(Formatter==null?"yyyy/MM/dd HH:mm:ss":Formatter);
        Date now = new Date(); 
        return dateFormat.format(now);
    }
    
    public static String getNow(){
    	return getNow(null);
    }
    
    public static void log(String msg) {  
        System.out.println(msg+"\n");  
    } 
    
    public static float floatRound(float f){
    	 return (float)(Math.round(f*100))/100;//(这里的100就是2位小数点,如果要其它位,如4位,这里两个100改成10000)
    }
    
    public static String getPrintTitle(String tableName)
    {
    	String result = null;
    	switch(tableName){
	    	case "tbl_MainRanking":result= "*****榜单*****\n\t";
	    	case "tbl_book":result= "*****书籍*****\n\t";
	    	case "tbl_booksource":result= "*****来源*****\n\t";
	    	case "tbl_chapters":result= "*****章节*****\n\t";
    	}
		return result;
    }
    
}
